package com.heima.behavior.listener;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.dto.FollowBehaviorDto;
import com.heima.behavior.service.IApFollowBehaviorService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
/**
 * 监听用户行为
 */
@Service
public class FollowListener {
    @Autowired
    private IApFollowBehaviorService apFollowBehaviorService;
    @KafkaListener(topics = "${topic.followBehaviorTopic}")
    public void handlerMsg(ConsumerRecord<String,String> consumerRecord){
        System.out.println("接收到消息 value = "+consumerRecord);
        FollowBehaviorDto dto = JSON.parseObject(consumerRecord.value(), FollowBehaviorDto.class);
        apFollowBehaviorService.saveFollow(dto);
    }
}
